package com.bilu.common.utility;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * 时间工具类
 */
public class TimeUtility {
	/**
	 * 格式化时间字符串
	 */
	public static String getFormatTime(Date time, String format){
		return new SimpleDateFormat(format).format(time);
	}
	
	/**
	 * 格式化时间字符串
	 */
	public static String getFormatTime(long time, String format){
		try {
			return new SimpleDateFormat(format).format(new Date(time));
		}catch(Exception e) {
			throw new RuntimeException(e);
		}
	}
	
	/**
	 * 格式化时间字符串
	 */
	public static String getFormatTime(Timestamp time, String format){
		try {
			return new SimpleDateFormat(format).format(time.getTime());
		}catch(Exception e) {
			return "";
		}
	}
	
	/**
	 * 将字符串解析成时间类型
	 */
	public static Date getDate(String time, String format){
		try {
			return new SimpleDateFormat(format).parse(time);
		}catch(Exception e) {
			throw new RuntimeException(e);
		}
	}
	
	/**
	 * 将字符串时间解析成毫秒数
	 */
	public static long getDateTime(String time, String format) {
		try {
			return new SimpleDateFormat(format).parse(time).getTime();
		}catch(Exception e) {
			throw new RuntimeException(e);
		}
	}
}
